package com.sgb.kjwl.view.ui.adapter.transport;

import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.GreyItemSimpleTabBinding;
import com.sgb.kjwl.databinding.ItemSimpleTabBinding;
import com.sgb.kjwl.model.entity.transport.TabEntity;

import org.jetbrains.annotations.Nullable;

import java.util.List;

public class GreySimpleTabAdapter extends BaseQuickAdapter<TabEntity, BaseViewHolder> {
    private int selectIndex;

    public GreySimpleTabAdapter(@Nullable List<TabEntity> data) {
        super(R.layout.grey_item_simple_tab, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TabEntity item) {
        GreyItemSimpleTabBinding binding = DataBindingUtil.bind(helper.itemView);
        if (binding == null) return;
        binding.llOrderTab.setSelected(selectIndex == helper.getLayoutPosition());
        binding.tvOrderTabTitle.setText(item.getTitle());
        binding.tvOrderTabCount.setVisibility(item.isShowBadge() ? View.VISIBLE : View.GONE);
        binding.tvOrderTabCount.setText(String.format("(%s)", item.getNumber() > item.getMaxNumber()
                ? String.format("%s+", item.getMaxNumber())
                : item.getNumber()));
        //
        if (helper.getLayoutPosition() == selectIndex) {
            binding.tvOrderTabTitle.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
            binding.tvOrderTabCount.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
        } else {
            binding.tvOrderTabTitle.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
            binding.tvOrderTabCount.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
        }
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
        notifyDataSetChanged();
    }
}
